package com.doit.demo01;

import java.io.*;
import java.net.Socket;

public class file_Client {
    public static void main(String[] args) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\DHG\\Desktop\\2021.5.22.jpg"));
        Socket socket = new Socket("localhost", 6666);
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());

        byte[] b = new byte[1024 * 8];
        int len;
        while ((len=bis.read(b))!=-1){
            bos.write(b,0 , len);
        }
        socket.shutdownInput();
        System.out.println("文件发送完毕");

        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[20];
        in.read(bytes);
        System.out.println(new String(bytes));

        socket.close();
        bis.close();
    }
}
